package ouisseuk.gui;

import java.util.List;

import ouisseuk.model.Artist;
import ouisseuk.model.ReleaseFromArtist;

import com.flexycore.iphone.uikit.NSIndexPath;
import com.flexycore.iphone.uikit.UIFont;
import com.flexycore.iphone.uikit.UIImage;
import com.flexycore.iphone.uikit.UITableView;
import com.flexycore.iphone.uikit.UITableViewCell;
import com.flexycore.iphone.uikit.UITableViewCellAccessoryType;
import com.flexycore.iphone.uikit.UITableViewDataSource;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
public class ReleasesFromArtistDataSource extends UITableViewDataSource {

	List<ReleaseFromArtist> releases;

	public ReleasesFromArtistDataSource(Artist artist) {
		super();
		init();
		releases = artist.getReleases();
	}

	@Override
	public int numberOfSectionsInTableView(UITableView tableView) {
		return 1;
	}

	@Override
	public int tableViewNumberOfRowsInSection(UITableView table, int section) {
		return releases.size();
	}

	//	@SuppressWarnings("unchecked")
	//	@Override
	//	public Vector sectionIndexTitlesForTableView(UITableView tableView) {
	//		Vector vector = new Vector();
	//		vector.add("Titeul");
	//		return vector;
	//	}

	@Override
	public UITableViewCell tableViewCellForRowAtIndexPath(UITableView tableView, NSIndexPath indexPath) {
		UITableViewCell cell = new UITableViewCell();
		cell.init();
		cell.setAccessoryType(UITableViewCellAccessoryType.UITableViewCellAccessoryDisclosureIndicator);
		cell.setIndentationLevel(0);
		UIImage icon;

		int row = indexPath.row();
		ReleaseFromArtist release = releases.get(row);
		cell.setText(release.getTitle());
		cell.setFont(UIFont.fontWithNameSize("Arial", 16));

		System.out.println("format: " + release.getFormat());

		if (release.getFormat().contains("CD"))
			icon = UIImage.imageNamed("cd-icon-32.png");
		else
			icon = UIImage.imageNamed("Vinyle-32.png");

		cell.setImage(icon);
		cell.setSelectedImage(icon);

		return cell;
	}
}
